package com.common.app.data.repository

import com.common.app.data.api.ApiConstant.getBaseUrl
import com.common.app.data.bean.bleDevice.CloudRingInfoBean
import com.common.base.data.CommonBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import rxhttp.toAwait
import rxhttp.wrapper.param.RxHttp

/**
 * 作者：sosou
 * <p>
 * 版本：1.0
 * <p>
 * 创建日期：2025/04/18
 * <p>
 * 描述：蓝牙设备
 * <p>
 * 修订历史：
 */
object BleDeviceApi {

    //戒指设备绑定
     val RING_DEVICE_BIND = getBaseUrl() + "api/v1/smart-ring/device/bind"
    //戒指设备解绑
    val RING_DEVICE_UNB_BIND = getBaseUrl() + "api/v1/smart-ring/device/unbind"
    //获戒指设备云端信息
    val GET_RING_DEVICE_INFO = getBaseUrl() + "api/v1/device/get"

    //戒指设备绑定
    suspend fun upBindRing(producer:Int,sn:String,firm:String,macAddr:String, size:Int, color:Int) =
        withContext(Dispatchers.IO) {
            RxHttp.postJson(RING_DEVICE_BIND)
                .add("Producer",producer)
                .add("Sn",sn)
                .add("FirmwareVersion",firm)
                .add("MacAddr",macAddr)
                .add("Size", size)
                .add("Color",color)
                .toAwait<CommonBean<CloudRingInfoBean>>()
                .await()
        }

    //戒指设备解绑
    suspend fun unBindRing(id:Int,) =
        withContext(Dispatchers.IO) {
            RxHttp.postJson(RING_DEVICE_UNB_BIND)
                .add("ID",id)
                .toAwait<CommonBean<String>>()
                .await()
        }

    //戒指设备解绑
    suspend fun getCloudRingInfo(imei:String,) =
        withContext(Dispatchers.IO) {
            RxHttp.postJson(GET_RING_DEVICE_INFO)
                .add("NO",imei)
                .toAwait<CommonBean<CloudRingInfoBean>>()
                .await()
        }
}